//
//  HJFrameAnimationView.m
//  KaiChat
//
//  Created by lx on 2023/11/28.
//

#import "HJFrameAnimationView.h"

@interface HJFrameAnimationView ()

@property (nonatomic, weak) UIImageView *imageView;
@property (nonatomic, assign) CGSize imageSize;

@end


@implementation HJFrameAnimationView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {

        UIImageView *imageView = [UIImageView addToView:self];
        imageView.animationDuration = 2;
        imageView.animationRepeatCount = 0;
        
        _imageView = imageView;
        _imageSize = CGSizeMake(27, 27);
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    _imageView.frame = CGRectMake((self.tj_width - _imageSize.width) * 0.5, (self.tj_height - _imageSize.height) * 0.5, _imageSize.width, _imageSize.height);
}
 
- (void)setImageNames:(NSArray *)imageNames {
    _imageNames = imageNames;
    
    NSMutableArray <UIImage *>*animationImages = [NSMutableArray array];
    [_imageNames enumerateObjectsUsingBlock:^(NSString *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIImage *uiImage = [UIImage imageNamed:obj];
        [animationImages addObject:uiImage];
    }];
    
    _imageView.animationImages = animationImages;
    [_imageView startAnimating];
}

@end
